/*
 * TemplatePanel.java
 *
 * Created on 9. Juni 2008, 22:12
 */

package twi.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import twi.query.QueryTemplate;

/**
 * 
 * @author Soeren
 */
public class TemplatePanel extends javax.swing.JPanel {

	/** Creates new form TemplatePanel */
	public TemplatePanel() {
		initComponents();
		setup();
	}

	private void setup() {
		updateTemplates();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated
	// Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jScrollPane2 = new javax.swing.JScrollPane();
		jPanel2 = new javax.swing.JPanel();

		jScrollPane2.setName("jScrollPane2"); // NOI18N

		jPanel2.setName("jPanel2"); // NOI18N

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
				jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 352,
				Short.MAX_VALUE));
		jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 497,
				Short.MAX_VALUE));

		jScrollPane2.setViewportView(jPanel2);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 354,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 499,
				Short.MAX_VALUE));
	}// </editor-fold>//GEN-END:initComponents

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JPanel jPanel2;
	private javax.swing.JScrollPane jScrollPane2;

	// End of variables declaration//GEN-END:variables
	public void updateTemplates() {
		this.jPanel2.removeAll();
		QueryTemplate.loadDatabase();
		this.jPanel2.setLayout(new GridBagLayout());
		GridBagConstraints gc = new GridBagConstraints();
		gc.fill = GridBagConstraints.BOTH;
		gc.gridheight = 1;
		gc.gridwidth = 1;
		gc.gridx = 0;
		gc.gridy = 0;
		for (int i = 0; i < QueryTemplate.templateDatabase.size(); i++) {
			this.jPanel2.add(new TemplatePreviewPanel(
					QueryTemplate.templateDatabase.get(i)), gc);
			gc.gridy++;
		}
	}

}
